<%--
  Created by IntelliJ IDEA.
  User: luren
  Date: 2021/9/8
  Time: 15:32
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html lang="zh">

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
    <title>欢迎注册</title>
    <link rel="stylesheet" href="style/style1.css" />
    <script src="js/jquery.min.js"></script>
    <script>
        function register() {
            let username = $('.username').val();
            let password = $('.password').val();
            let name = $('.name').val();
            let phone = $('.phone_number').val();
            let level = $('.level').val();
            $.ajax({
                url: 'register.do',
                data: { 'username': username, 'password': password, 'name': name, 'phone': phone, 'level': level },
                success: function (request) {
                    if (request === 'error') {
                        alert('注册失败');
                    } else if (request === 'ok')
                    {
                        top.location = '/' + window.location.pathname.split('/')[1] + '/login.jsp';
                    } else {
                        alert(request);
                    }
                },
                error: function (error) {
                    alert('服务器繁忙，请稍后重试')
                }
            })
        }

    </script>
</head>

<body>

<div class="register-container">
    <h1>用户注册</h1>

    <div class="connect">
        <p>欢迎来到空调售卖平台</p>
    </div>

    <form action="" method="post" id="registerForm">
        <div>
            <input type="text" name="username" class="username" placeholder="您的用户名" autocomplete="off" />
        </div>
        <div>
            <input type="password" name="password" class="password" placeholder="输入密码" oncontextmenu="return false" onpaste="return false" />
        </div>
        <div>
            <input type="password" name="confirm_password" class="confirm_password" placeholder="再次输入密码" oncontextmenu="return false" onpaste="return false" />
        </div>
        <div>
            <input type="name" name="name" class="name" placeholder="输入姓名" oncontextmenu="return false" onpaste="return false" />
        </div>
        <div>
            <input type="text" name="phone_number" class="phone_number" placeholder="输入手机号码" autocomplete="off" id="number" />
        </div>
        <div>
            <input type="radio" class="level" name="level" value="1" checked>用户
            <input type="radio" class="level" name="level" value="2" aria-label="商家">商家
        </div>


    </form>
    <button id="button" onclick="register()">注 册</button>

    <a id="register-tis" href="login.jsp">
        <button type="button" class="register-tis">已经有账号？</button>
    </a>

</div>


<script src="js/common.js"></script>
<!--背景图片自动更换-->
<script src="js/supersized.3.2.7.min.js"></script>
<script src="js/supersized-init.js"></script>
<!--表单验证-->
<script src="js/jquery.validate.min.js?var1.14.0"></script>

</body>

</html>
